home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 1.1 / SGI EnlightenDSM 1.1.iso / sco5x / emd / bin / ClearEvents < prev    next >
Text File  |  1998-06-30  |  3KB  |  140 lines

  1. # !/bin/sh
  2. #
  3. # Usage: ClearEvents hostname
  4. #
  5. # This script will clear all uncleared events for the specified host
  6. # Requirements:
  7. #  1. This script must be run by user dbenl.
  8. #  2. AgentMon must be running on the same machime the script is run from.
  9. #  3. Pep must be running.
  10. #
  11. # Copyright (c) 1990-1998 Enlighten Software Solutions, Inc.
  12. # All rights reserved
  13. #
  14.  
  15.  
  16. # Make sure proper arguments supplied
  17. if [ $# -ne 1 ] ; then
  18.     echo "Usage: ClearEvents <hostname>"
  19.     echo "This program will clear all uncleared events for the specified host."
  20.     echo "Requirements:"
  21.     echo " 1. This program must be run by user dbenl."
  22.     echo " 2. AgentMon must be running on the machine you run this program on."
  23.     echo " 3. Pep must be running."
  24.     exit 1
  25. fi
  26.  
  27. host=$1
  28. emd_dir=`pwd`
  29.  
  30. # Find enlighten directory
  31. if [ ! -f /etc/enlighten ] ; then
  32.     echo "File /etc/enlighten not found...Exiting"
  33.     exit 1
  34. fi
  35.  
  36. enl=`egrep "^enlighten=" /etc/enlighten | cut "-d=" -f2-`
  37. enl_bin=${enl}/bin
  38.  
  39. if [ ! -d $enl_bin ] ; then
  40.     echo "Enlighten directory $enl_bin not found...Exiting"
  41.     exit 1
  42. fi
  43.  
  44. if [ ! -x ${enl_bin}/EventsCli ] ; then
  45.     echo "Unable to execute $enl_bin/EventsCli...Exiting"
  46.     exit 1
  47. fi
  48.  
  49.  
  50.  
  51. # Create temporary files
  52. temp1="getevents.sql"
  53. temp2="names.tmp"
  54. temp3="clear-env.tmp"
  55.  
  56.  
  57. touch $temp1
  58. if [ ! -f $temp1 ] ; then
  59.     echo "Unable to create temporary file $temp1 in current directory"
  60.     echo "Exiting..."
  61.     exit 1
  62. fi
  63.  
  64. touch $temp2
  65. if [ ! -f $temp2 ] ; then
  66.     echo "Unable to create temporary file $temp2 in current directory"
  67.     echo "Exiting..."
  68.     rm $temp1
  69.     exit 1
  70. fi
  71.  
  72. touch $temp3
  73. if [ ! -f $temp3 ] ; then
  74.     echo "Unable to create temporary file $temp3 in current directory"
  75.     echo "Exiting..."
  76.     rm $temp1
  77.     rm $temp2
  78.     exit 1
  79. fi
  80.  
  81. chmod a+rw  $temp1
  82. chmod a+rw  $temp2
  83. chmod a+rwx $temp3
  84.  
  85. # Remeber hostname for later use by awk script
  86.  
  87. echo "host_name $host" > $temp2
  88.  
  89. # Create sql select statements
  90.  
  91. echo "select a.test_index, MAX(a.timestamp) mytime, b.class from events_tbl a, event_index_tbl b  where a.host_index = (select host_index from host_index_tbl where host_name = \"$host\" ) and a.test_index = b.test_index group by a.test_index, b.class into TEMP tbla ;" > $temp1
  92.  
  93. echo  >> $temp1
  94.  
  95. echo "select a.severity, b.class, c.test_name from events_tbl a, tbla b, event_index_tbl c where a.test_index = b.test_index and c.test_index = b.test_index and a.timestamp = b.mytime into temp tblb;" >> $temp1
  96.  
  97. echo  >> $temp1
  98.  
  99. echo "select class, test_name from tblb where severity > 1;" >> $temp1
  100.  
  101. # Execute sql statements
  102. echo "Querying database for uncleared events...."
  103. echo
  104.  
  105. dbaccess enlighten $temp1 >> $temp2 2> /dev/null
  106.  
  107. # Check on results
  108.  
  109. num=`grep test_name $temp2 | wc -l | awk '{print $1}'`
  110.  
  111. if [ "$num" -eq 0 ] ; then
  112.     echo "No events found which need to be cleared"
  113.     rm $temp1
  114.     rm $temp2
  115.     rm $temp3
  116.     exit 0
  117. fi
  118.  
  119. echo "Number of events found: $num "
  120. echo
  121.  
  122. # Create command file
  123.  
  124. awk ' { { if( $1 == "host_name" ) { myhost = $2 ; break }} { if( $1 == "class" ) { myclass = $2 ; break }} { if ( $1 == "test_name" ) { printf("echo Clearing event for test \"%s\"...\n", substr($0,index($0, $2), 255)) ; printf("./EventsCli  -c %s -s 1 -h %s -q -n \"%s\"\n", myclass, myhost, substr($0,index($0, $2), 255)) } } } \
  125.    ' $temp2 > $temp3
  126.  
  127.  
  128. # Execute command file
  129. cd $enl_bin
  130. ${emd_dir}/$temp3
  131.  
  132. # Cleanup
  133. cd $emd_dir
  134. rm $temp1
  135. rm $temp2
  136. rm $temp3
  137.  
  138. echo
  139. echo "Done."
  140.